﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Quan_ly_thong_tin_he_thong
{
    public partial class HoaDonChiTiet : Form
    {
        public HoaDonChiTiet()
        {
            InitializeComponent();
        }

       
        private void HoaDonChiTiet_Load(object sender, EventArgs e)
        {
            LoadDataGridView();
            LoadComMSHD();
            LoadComMSSP();
        }
        private void LoadDataGridView()
        {
            Config file = new Config(Application.StartupPath + "\\Config.ini");
            string connectionstring = file.ReadValue("server", "con");
            SqlConnection conn = new SqlConnection(connectionstring);
            string sql = "select HoaDon_CT.MaSo_HD ,HoaDon_CT.MaSo_SP ,Ten_SP,SoLuong from HoaDon_CT join SanPham on HoaDon_CT.MaSo_SP=SanPham.MaSo_SP   ";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            conn.Open();

            DataSet ds = new DataSet();
            adapter.Fill(ds, "HoaDon_CT");
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = ds.Tables["HoaDon_CT"];
            conn.Close();
        }
        private void LoadComMSHD()
        {
            Config file = new Config(Application.StartupPath + "\\Config.ini");
            string connectionstring = file.ReadValue("server", "con");
            SqlConnection conn = new SqlConnection(connectionstring);
            string sql = "select * from HoaDon_CT";
      
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            conn.Open();

            DataSet ds = new DataSet();
            adapter.Fill(ds, "HoaDon_CT");
            DataTable dt = ds.Tables["HoaDon_CT"];
            comMSHD.DisplayMember = "MaSo_HD";
            comMSHD.ValueMember = "MaSo_HD";
            comMSHD.DataSource = ds.Tables["HoaDon_CT"].DefaultView;
            conn.Close();
        }
        private void LoadComMSSP()
        {
            Config file = new Config(Application.StartupPath + "\\Config.ini");
            string connectionstring = file.ReadValue("server", "con");
            SqlConnection conn = new SqlConnection(connectionstring);
            string sql = "select * from SanPham ";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            conn.Open();

            DataSet ds = new DataSet();
            adapter.Fill(ds, "SanPham");
            DataTable dt = ds.Tables["SanPham"];
            comMSSP.DisplayMember = "Ten_SP";
            comMSSP.ValueMember = "MaSo_SP";
            comMSSP.DataSource = ds.Tables["SanPham"].DefaultView;
            conn.Close();
        }

      

       

        

    }
}
